#ifndef AUTOUPDATEFILE_H
#define AUTOUPDATEFILE_H

/*****************************************************************
 如果HTTPS下载，需要配置SSL，以下为配置说明：
 MinGW编译：
 32位 拷贝D:\Qt\Qt5.12.3\Tools\mingw730_32\opt\bin路径下libeay32.dll、ssleay32.dll 到D:\Qt\Qt5.12.3\5.12.3\mingw73_32\bin
 64位 拷贝D:\Qt\Qt5.12.3\Tools\mingw730_64\opt\bin路径下libeay32.dll、ssleay32.dll 到D:\Qt\Qt5.12.3\5.12.3\mingw73_64\bin
 Windows编译：
 1、安装对应OpenSSL版本，下载地址https://www.openssl.org/
 2、安装成功后配置环境变量
 3、INCLUDEPATH += D:/Program Files (x86)/OpenSSL-Win32/include
 4、拷贝OpenSSL安装目录下libcrypto-1_1.dll、libssl-1_1.dll文件到D:\Qt\Qt5.12.3\5.12.3\msvc2017\bin (注意编译版本及32/64位都要对应)
 Linux编译：

 如果需要解压缩，需要依赖quazip、zlib库
mingw编译zlib
1、 mingw32-make -f win32/makefile.gcc
******************************************************************/
#include <QObject>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>

struct DownloadInfo
{
    double  speed;
    double  leftTime;
    qint64  bytesReceived;
    qint64  bytesTotal;
};

class AutoUpdateFile : public QObject
{
    Q_OBJECT
public:
    AutoUpdateFile();

    void    setFilePath(const QString& filePath);
    void    requestUrl(QUrl url);
    void    startDown(QUrl url);
    void    unzipFile();
signals:
    void replyFinished(QByteArray array);
    void replyError(QVariant stateCode);
    void downloadProgress(const DownloadInfo* downloadInfo);
    void downloadFinished(int stateCode);
    void downloadError(const QString& error);
private slots:
    void finished(QNetworkReply *reply);
    void downFinished(QNetworkReply *reply);
    void downProgress(qint64 bytesReceived, qint64 bytesTotal);
    void readyRead();
private:
    QNetworkAccessManager       *m_NetManager;

    QNetworkAccessManager       *m_NetManagerDownload;
    QNetworkReply               *m_DownloadReply;
    QTime                       m_DownloadTime;

    int                         m_nTime;
    QString                     m_FilePath;
    QString                     m_FileName;

    DownloadInfo                *m_DownloadInfo;
};

#endif // AUTOUPDATEFILE_H
